<template>
  <div class="header">
    <div class="page-title">洗车订单</div>
    <el-form :inline="true" :model="form" class="demo-form-inline">
      <el-form-item label="车牌号">
        <el-input v-model="form.license" placeholder="车牌号"></el-input>
      </el-form-item>
      <el-form-item label="门店">
        <el-select v-model="form.store_id" placeholder="门店">
          <el-option label="请选择" value="0"></el-option>
          <el-option
              v-for="item in listData"
              :key="item.id"
              :label="item.name"
              :value="item.id">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="商户"  v-if="isAdmin=='admin'">
        <el-select v-model="form.manager_id" placeholder="商户">
          <el-option label="请选择" value="0"></el-option>
          <el-option
              v-for="manager in managerData"
              :key="manager.id"
              :label="manager.username"
              :value="manager.id">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSubmit">查询</el-button>
      </el-form-item>
    </el-form>
    <el-table :data="tableData" class="m-t-5">
      <el-table-column type="selection" width="55"></el-table-column>
      <el-table-column prop="id" label="id" width="100"></el-table-column>
      <el-table-column prop="manager" label="商户名称"></el-table-column>
      <el-table-column prop="store_name" label="门店名称"></el-table-column>
      <el-table-column prop="station.name" label="工位名称" ></el-table-column>
      <el-table-column prop="create_time" label="开始时间" ></el-table-column>
      <el-table-column prop="end_time" label="结束时间" ></el-table-column>
      <el-table-column prop="license" label="车牌号" ></el-table-column>
      <el-table-column prop="price" label="费用价格（结账后生成）" ></el-table-column>
      <el-table-column prop="pay_status" label="是否已扣费" ></el-table-column>
      <el-table-column
        prop="is_pay"
        label="是否使用赠送分钟数"
      >
        <template #default="v">
          <text v-if="v.row.recharge_send_id > 0">是</text>
          <text v-else>否</text>
        </template>
      </el-table-column>
      <el-table-column prop="joinUser.wxname" label="进门用户昵称" ></el-table-column>
      <el-table-column prop="outUser.wxname" label="出门用户昵称" ></el-table-column>
      <el-table-column label="操作" min-width="200">
        <template #default="v">
          <el-button
            type="danger"
            size="mini"
            icon="el-icon-delete"
            @click="handleDelete(v.row)"
            >删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      background
      hide-on-single-page
      layout="prev, pager, next"
      :total="total"
      :current-page="current"
      @current-change="changePage"
    >
    </el-pagination>
  </div>

  <el-dialog title="公告操作" v-model="dialogFormVisible" width="35%">
    <el-form>
      <el-form-item label="公告内容">
        <el-input
          v-model="form.content"
          autocomplete="off"
          placeholder="请输入名称"
        ></el-input>
      </el-form-item>
    
      <el-form-item label="排序">
        <el-input
          v-model="form.sort"
          autocomplete="off"
          placeholder="请输入排序"
        ></el-input>
      </el-form-item>
    </el-form>

    <template v-slot:footer>
      <div class="dialog-footer">
        <el-button @click="dialogFormVisible = false">取 消</el-button>
        <el-button type="primary" @click="handleSubmitForm">确 定</el-button>
      </div>
    </template>
  </el-dialog>
</template>
<script>

import { request_distinguish_log,request_order_delete,request_store_lists,request_get_managers} from "@/util/api";

export default {
  name: "SeekType",
  data() {
    return {
      current: 1,
      isAdmin:JSON.parse(sessionStorage.getItem('userinfo')).username,
      total: 0,
      listData:{},
      managerData:{},
      form: {
        license:'',
        store_id:'',
        manager_id:'',
        page:1
      },
      dialogFormVisible: false,
      actionType: 0, // 1 添加  2 编辑
    };
  },
  computed: {},
  mounted() {
    this.init();
  },
  methods: {
    init() {
        this.changePage(1);
        this.getStoreLists()
        this.getManagerLists()
    },
    //查询门店列表
    getStoreLists(){
      request_store_lists().then((res)=>{
        const result = res.data;
        if (result.code == 200) {
          this.listData = result.data;
        }
      }).catch()
    },
    //查询商户列表
    getManagerLists(){
      request_get_managers().then((res)=>{
        const manage = res.data;
        if(manage.code==200){
          this.managerData = manage.data;
        }
      }).catch()
    },
    /**
     * 条件查询列表
     */
    onSubmit(){
      request_distinguish_log(this.form).then((res)=>{
        const result = res.data;
        if(result.code == 200){
          this.tableData = result.data.data;
          this.total = result.data.total;
          this.current = result.data.current;
        }
      }).catch()
    },
    // 删除
    handleDelete(row) {
      this.$confirm("此操作将永久删除，是否继续？", "系统提示", {
        type: "warning",
        confirmButtonText: "确定",
        cancelButtonText: "取消",
      })
        .then(() => {
          request_order_delete({
            id: row.id,
          })
            .then((res) => {
              const result = res.data;
              if (result.code == 200) {
                this.$message.success({
                  message: "删除成功！",
                  offset: 70,
                });
                this.changePage(this.page)
              } else {
                this.$message.error({
                  message: result.message,
                  offset: 70,
                });
              }
            })
            .catch();
        })
        .catch(() => {
          this.$message.info({
            message: "已取消删除！",
            offset: 70,
          });
        });
    },
    // 分页
    changePage(page) {
      request_distinguish_log({
        page,
      })
        .then((res) => {
          const result = res.data;
          if (result.code == 200) {
            this.tableData = result.data.data;
            this.total = result.data.total;
            this.current = result.data.current;
          }
        })
        .catch();
    },
  },
};
</script>

<style scoped  lang="less">
</style>